package com.example.administrator.szb.view;

import android.content.Context;
import android.graphics.Canvas;
import android.text.SpannableStringBuilder;
import android.widget.TextView;

/**
 * Created by stone on 2018/2/3.
 */

public class MyTextViews extends TextView {
    public MyTextViews(Context context) {
        super(context);
    }
    protected void onDraw(Canvas canvas) {
        CharSequence charSequence = getText() ;
        int lastCharDown = getLayout().getLineVisibleEnd(0) ;
        if (charSequence.length() > lastCharDown){
            SpannableStringBuilder spannableStringBuilder = new SpannableStringBuilder() ;
            spannableStringBuilder.append(charSequence.subSequence(0,lastCharDown-4)).append("...") ;
            setText(spannableStringBuilder);
        }
        super.onDraw(canvas);
    }
}
